<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <base th:href="${#request.getContextPath() + '/system/'}"/>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    <!-- Invalid Stylesheet. This makes stuff look pretty. Remove it if you want the CSS completely valid -->
    <!-- Reset Stylesheet -->
    <link rel="stylesheet" href="resources/css/reset.css" type="text/css"
          media="screen"/>
    <!-- Main Stylesheet -->
    <link rel="stylesheet" href="resources/css/style.css" type="text/css"
          media="screen"/>
    <link rel="stylesheet" href="resources/css/invalid.css" type="text/css"
          media="screen"/>

    <!--                       Javascripts                       -->
    <!-- jQuery -->
    <script type="text/javascript"
            src="resources/scripts/jquery-1.3.2.min.js"></script>
    <!-- jQuery Configuration
    <script type="text/javascript"
            src="resources/scripts/simpla.jquery.configuration.js"></script>-->

    <!-- 引入ztree -->
    <link rel="stylesheet" href="resources/widget/zTree/zTreeStyle/zTreeStyle.css"/>
    <script type="text/javascript" src="resources/widget/zTree/jquery.ztree.all.min.js"></script>

    <script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/myajax.js'}"></script>
    <script type="text/javascript" th:src="${#request.getContextPath() + '/commons/js/myztree.js'}"></script>

    <script th:inline="javascript">


        /**
         * 修改终端ip地址
         */
        function updateGolangIp(){
            var ip = $("#ip_address").val();
            var port = $("#port").val();

            //判断ip
            var str = /^((25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))\.){3}(25[0-5]|2[0-4]\d|((1\d{2})|([1-9]?\d)))$/;
            var str3 = /^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$/;
            if(!str.test(ip) && !str3.test(ip)){
                alert("ip地址的格式不正确！");
                return;
            }

            //判断端口
            var str2 = /^\d{0,65535}$/;
            if(!str2.test(port)){
                alert("端口必须是0~65536之间的正整数！");
                return;
            }

            myajax({
                type: "POST",
                url: "/golang/updateip",
                data: {"ip":ip, "port":port},
                success: function(data){
                    alert("终端ip修改成功！");
                }
            });
        }
    </script>

</head>
<body>
<div id="main-content">
    <div class="content-box">
        <!-- End .content-box-header -->
        <div class="content-box-content">
            <h2>终端ip管理</h2>

            IP地址：<input id="ip_address" type="text" name="ip_address" th:value="${golangHost}" placeholder="Golang服务器的ip地址"/><br/>
            端口：<input id="port" type="text" name="port" th:value="${golangPort}" placeholder="Golang服务器的端口号"/><br/>

            <p>
                <button class="mybutton" type="submit" onclick="updateGolangIp();">修改ip</button>
            </p>

        </div>
        <!-- End .content-box-content -->
    </div>
</div>
<!-- End #main-content -->
</body>
</html>